#include "cronistaMenu.h"

void cronistaMenu(struct UserVars userData){
	struct PlantillaVars *rosters;
	loadPlantillas("data/Plantillas.txt",&rosters);
	struct EquipoVars *teams;
	loadEquipos("data/Equipos.txt",&teams);
	struct FutbolistaVars *players;
	loadFutbolistas("data/Futbolistas.txt",&players);

	int run=1;
	int op;
	system("clear");
    printf("Welcome %s\n",userData.name);
	while(run){
        printf("*****Cronista Menu*****\n");
        printf("Select an option\n");
        printf("<1>List Teams\n");
        printf("<2>Evaluate Teams\n");
        printf("<6>Exit\n");
        scanf("%d",&op);
		char ch = getchar();
		int change=0;
		switch(op){
			case 1:
				listTeams(teams,players);
				break;
			case 2:
				change=1;
				break;
			case 3:
				break;
			case 4:
				break;
			case 6:
				run=0;
				break;
		}
	}
	free(teams);
	writeFutbolistas("outputfiles/newFutbolistas.txt",players);
}

void listTeams(struct EquipoVars *teams,struct FutbolistaVars *players){
	printf("TEAMS:\n");
	for(int i=0;i<equipocount;i++){
		printf("ID:%d Team name:%s\n",teams[i].id,teams[i].name);
		printf("\tPlayers:\n");
		for(int j=0;j<futbolistacount;j++){
			if(players[j].teamID == teams[i].id){
				printf("\tName:%s Value:%d\n",players[j].name,players[j].value);
			}
		}
	}
}
